package com.youxuan.controller;

import com.youxuan.pojo.entity.ResponseResult;
import com.youxuan.pojo.vo.AddCartGoodsParamVo;
import com.youxuan.pojo.vo.GoodsVo;
import com.youxuan.service.CartService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
@Api(tags = "购物车")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/goods/list/{uid}")
    @ApiOperation("获取用户购物车商品列表")
    @ApiImplicitParam(name = "uid",value = "用户id",required = true)
    public ResponseResult getUserCart(@PathVariable("uid") Long uid) {
        List<GoodsVo> goodsVos = cartService.getUserCartGoodsList(uid);
        return ResponseResult.okResult(goodsVos);
    }

    @PostMapping("/add/goods")
    @ApiOperation("添加商品到购物车")
    public ResponseResult addCartGoods(@RequestBody AddCartGoodsParamVo addCartGoodsParamVo){
        cartService.addCartGoods(addCartGoodsParamVo);
        return ResponseResult.okResult();
    }


}
